home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / easybar.zip / BARDEMO.C next >
C/C++ Source or Header  |  1995-01-19  |  29KB  |  1,029 lines

  1. // bardemo.c
  2.  
  3. #include "windows.h"
  4. #include "commdlg.h"
  5. #include "stdlib.h"
  6. #include "string.h"
  7.  
  8. #include "resource.h"
  9. #include "easybar.h"
  10.  
  11. typedef struct tagLONGSTRING
  12. {
  13.     long    id;
  14.     char    *szName;
  15.  
  16. } LONGSTRING;
  17.  
  18. LONGSTRING g_styles[] =
  19. {
  20.     BDF_LEFT,"Left"
  21.     ,BDF_RIGHT, "Right"
  22.     ,BDF_TOP, "Top"
  23.     ,BDF_BOTTOM, "Bottom"
  24.     ,BDF_CENTER, "Center"
  25.     ,BDF_VCENTER, "VCenter"
  26.     ,BDF_HIDEMAINTEXT, "HideMainText"
  27.     ,BDF_HIDEADDONTEXT, "HideAddOnText"
  28.     ,BDF_ADDONTEXTATTOP, "AddOnTextAtTop"
  29.     ,BDF_ADDONTEXTATBOTTOM, "AddOnTextAtBottom"
  30.     ,BDF_MAINTEXTATTOP, "MainTextAtTop"
  31.     ,BDF_MAINTEXTATBOTTOM, "MainTextAtBottom"
  32.     ,BDF_NOUPCSMALLFONT, "NoUpcSmallFont"
  33.     ,BDF_NOSTRETCHTEXT, "NoStretchText"
  34.     ,BDF_UNIBARHEIGHT, "UniBarHeight"
  35.     ,BDF_RETAINASPECTRATIO, "RetainAspectRatio"
  36.     ,BDF_NOPIXELALIGN, "NoPixelAlign"
  37.     ,BDF_CALCSIZEONLY, "CalcSizeOnly"
  38. };
  39.  
  40. HBARCODE     g_hbar = 0;
  41. RECT        g_rcCanvas;
  42. RECT        g_rc;
  43. int            g_iOrient = 0;
  44. DWORD        g_style = 0;
  45. int            g_iType = 0;
  46. LOGFONT        g_logfont;
  47. char        g_tmp[100];
  48. COLORREF    g_clfFg;
  49. COLORREF    g_clfBg;
  50. int            g_iBkMode;
  51. HGLOBAL        g_hDevMode = 0;
  52. HGLOBAL        g_hDevNames = 0;
  53. HDC            g_hPrintDC = 0;
  54. BOOL        g_bUserAbort = FALSE;
  55. HWND        g_hPrintDlg = 0;
  56. BOOL        g_bInvalidData1 = FALSE;
  57. BOOL        g_bInvalidData2 = FALSE;
  58.  
  59. #define HT_INSIDE        1
  60. #define HT_LEFT            2
  61. #define HT_RIGHT        3
  62. #define HT_TOP            4
  63. #define HT_BOTTOM        5
  64. #define HT_LEFTTOP        6
  65. #define HT_RIGHTTOP        7
  66. #define HT_RIGHTBOTTOM    8
  67. #define HT_LEFTBOTTOM    9
  68.  
  69. long FAR PASCAL _export WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  70. BOOL FAR PASCAL _export AboutDlgProc(HWND hwnd, UINT msg, 
  71.                             WPARAM wParam, LPARAM lParam);
  72. BOOL FAR PASCAL _export AdvancedDlgProc(HWND hwnd, UINT msg, 
  73.                             WPARAM wParam, LPARAM lParam);
  74. BOOL FAR PASCAL _export AbortProc(HDC hdcPrint, short sCode);
  75. BOOL FAR PASCAL _export PrintDlgProc(HWND hDlg, UINT msg, 
  76.                             WPARAM wParam, LPARAM lParam);
  77. static void drawBarcode(HWND hwnd, HDC hdc, HDC hicTarget, 
  78.                 HBARCODE hBar, LPRECT lprc);
  79. static void printBarcode(HWND hwnd, HDC hdcPrint, 
  80.                 HBARCODE hBar, LPRECT lprc);
  81. static long cmdProc(HWND hwnd, WPARAM wParam, LPARAM lParam);
  82. static void XORDottedFrame (HDC hdc, LPRECT prc);
  83. static DWORD getStyle(HWND hwnd);
  84. static int hitTest(int x, int y, LPRECT lprc);
  85.  
  86. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, 
  87.                 LPSTR lpszCmdLine, int nCmdShow)
  88. {
  89.     static char szAppName[] = "Easybar";
  90.     HWND    hwnd;            
  91.     MSG        msg;                                    
  92.     
  93.     if (!hPrevInstance)
  94.     {
  95.         WNDCLASS    cs;
  96.         
  97.         cs.style = CS_HREDRAW | CS_VREDRAW;
  98.         cs.lpfnWndProc = WndProc;
  99.         cs.cbClsExtra = 0;
  100.         cs.cbWndExtra = DLGWINDOWEXTRA;
  101.         cs.hInstance = hInstance;
  102.         cs.hIcon = LoadIcon(hInstance, "BARDEMO");
  103.         cs.hCursor = NULL; //LoadCursor(hInstance, IDC_ARROW);
  104.         cs.hbrBackground = COLOR_WINDOW + 1;
  105.         cs.lpszMenuName = NULL;
  106.         cs.lpszClassName = szAppName;
  107.  
  108.         RegisterClass(&cs);
  109.     }
  110.  
  111.     hwnd = CreateDialog(hInstance, szAppName, 0, NULL);
  112.     
  113.     ShowWindow(hwnd, nCmdShow);
  114.     UpdateWindow(hwnd);
  115.     
  116.     while(GetMessage(&msg, NULL, 0, 0))
  117.     {
  118.         if (!IsDialogMessage(hwnd, &msg))
  119.         {
  120.             TranslateMessage(&msg);
  121.             DispatchMessage(&msg);
  122.         }
  123.     }
  124.  
  125.     return msg.wParam;
  126. }
  127.  
  128. long FAR PASCAL _export WndProc(HWND hwnd, UINT msg, 
  129.                             WPARAM wParam, LPARAM lParam)
  130. {                        
  131.     HWND        hctl;                  
  132.     int            iType;          
  133.     int            i, ind;
  134.     LPSTR        lp;                             
  135.     PAINTSTRUCT    ps;
  136.     HDC            hdc;
  137.     HFONT        hFont, hFont0;
  138.     HBRUSH        hBrush;
  139.     static PRINTDLG        pd;
  140.     static        bInitialized = FALSE;
  141.     static        nDrag = 0;  
  142.     static POINT    pt;
  143.     static RECT        rcPrev;     
  144.     static TEXTMETRIC    tm;
  145.     
  146.     switch(msg) {                                   
  147.     case WM_CREATE:
  148.         memset(&pd, 0, sizeof(pd));
  149.         pd.lStructSize = sizeof(pd);
  150.         pd.hwndOwner = hwnd;
  151.         pd.Flags = PD_RETURNDC | PD_RETURNDEFAULT;
  152.         if (PrintDlg(&pd)) 
  153.         {
  154.             g_hPrintDC = pd.hDC;
  155.             g_hDevMode = pd.hDevMode;
  156.             g_hDevNames = pd.hDevNames;
  157.         }
  158.         return 0;
  159.     case WM_MOVE:
  160.         if (bInitialized) break;
  161.         bInitialized = TRUE;
  162.         g_hbar = 0;
  163.         for (i = 0; (i = EnumBarcodeTypes(i, &iType, &lp)) != 0; )
  164.         {
  165.             ind = (int)SendDlgItemMessage(hwnd, IDC_BARCODE, CB_ADDSTRING, 
  166.                                         0, (LONG)lp);
  167.             SendDlgItemMessage(hwnd, IDC_BARCODE, CB_SETITEMDATA, 
  168.                                         ind, (LONG)iType);
  169.         }
  170.         SendDlgItemMessage(hwnd, IDC_BARCODE, CB_SETCURSEL, 0, 0);
  171.            iType = (int) SendDlgItemMessage(hwnd, IDC_BARCODE, 
  172.                         CB_GETITEMDATA, (WPARAM)0, (LPARAM)0);
  173.         g_hbar = BarCreate(iType, 0);
  174.         g_iType = iType;
  175.  
  176.         BarGetData(g_hbar, g_tmp, sizeof(g_tmp), NULL, 0);
  177.         SendDlgItemMessage(hwnd, IDC_DATA, WM_SETTEXT, 0, 
  178.                 (LONG)(LPSTR)g_tmp);
  179.  
  180.         BarGetAddOnData(g_hbar, g_tmp, sizeof(g_tmp), NULL, 0);
  181.         if (!g_tmp[0])
  182.         {
  183.             EnableWindow(GetDlgItem(hwnd, IDC_ADDONDATA), FALSE);
  184.             EnableWindow(GetDlgItem(hwnd, IDC_ADDONMESG), FALSE);
  185.         }
  186.         else
  187.         {
  188.             SendDlgItemMessage(hwnd, IDC_ADDONDATA, WM_SETTEXT, 0, 
  189.                 (LONG)(LPSTR)g_tmp);
  190.         }
  191.         
  192.         SendDlgItemMessage(hwnd, IDC_ORIENT, CB_ADDSTRING, 0, (LONG)(LPSTR)"0");
  193.         SendDlgItemMessage(hwnd, IDC_ORIENT, CB_ADDSTRING, 0, (LONG)(LPSTR)"90");
  194.         SendDlgItemMessage(hwnd, IDC_ORIENT, CB_ADDSTRING, 0, (LONG)(LPSTR)"180");
  195.         SendDlgItemMessage(hwnd, IDC_ORIENT, CB_ADDSTRING, 0, (LONG)(LPSTR)"270");
  196.         SendDlgItemMessage(hwnd, IDC_ORIENT, CB_SETCURSEL, 0, 0);
  197.         g_iOrient = 0;
  198.  
  199.         for (i = 0; i < sizeof(g_styles) / sizeof(g_styles[0]); i++)
  200.         {
  201.             ind = (int) SendDlgItemMessage(hwnd, IDC_STYLE, LB_ADDSTRING, 
  202.                     (WPARAM)0, (LONG)(LPSTR)(g_styles[i].szName));
  203.             SendDlgItemMessage(hwnd, IDC_STYLE, LB_SETITEMDATA,
  204.                     (WPARAM)ind, (LPARAM)g_styles[i].id);
  205.         }
  206.  
  207.         // init font
  208.         hdc = GetDC(hwnd);   
  209.         hFont0 = SelectObject(hdc, GetStockObject(DEVICE_DEFAULT_FONT));
  210.         GetObject(hFont0, sizeof(g_logfont), (LPSTR)&g_logfont);
  211.         strcpy(g_logfont.lfFaceName, "Arial");
  212.         g_logfont.lfOutPrecision = OUT_TT_ONLY_PRECIS;
  213.         g_logfont.lfClipPrecision = CLIP_TT_ALWAYS;
  214.         g_logfont.lfWidth = 0;
  215.         hFont = CreateFontIndirect(&g_logfont);
  216.         SelectObject(hdc, hFont);
  217.         GetTextFace(hdc, LF_FACESIZE, g_logfont.lfFaceName);
  218.         GetTextMetrics(hdc, &tm);
  219.         if (tm.tmHeight < 0)
  220.             i = tm.tmHeight;
  221.         else
  222.             i = -(tm.tmHeight - tm.tmInternalLeading);
  223.         g_logfont.lfHeight = i;
  224.         wsprintf(g_tmp, "%d", MulDiv(-i, 72, GetDeviceCaps(hdc, LOGPIXELSY)));
  225.         SetWindowText(GetDlgItem(hwnd, IDC_POINT), g_tmp);
  226.         SetWindowText(GetDlgItem(hwnd, IDC_FONTNAME), g_logfont.lfFaceName);
  227.         SelectObject(hdc, hFont0);
  228.         DeleteObject(hFont);
  229.  
  230.         // init color
  231.         g_clfFg = GetTextColor(hdc);
  232.         g_clfBg = GetBkColor(hdc);
  233.         g_iBkMode = GetBkMode(hdc);
  234.         if (g_iBkMode == TRANSPARENT) 
  235.             SendDlgItemMessage(hwnd, IDC_TRANSPARENT, BM_SETCHECK, 1, 0);
  236.         else
  237.             SendDlgItemMessage(hwnd, IDC_TRANSPARENT, BM_SETCHECK, 0, 0);
  238.         
  239.         ReleaseDC(hwnd, hdc);
  240.  
  241.         hctl = GetDlgItem(hwnd, IDC_CANVAS);
  242.         GetWindowRect(hctl, &g_rcCanvas);
  243.         g_rcCanvas.right += 5;
  244.         g_rcCanvas.bottom += 5;
  245.         ScreenToClient(hwnd, (LPPOINT)&g_rcCanvas);
  246.         ScreenToClient(hwnd, ((LPPOINT)&g_rcCanvas) + 1);
  247.         MoveWindow(hctl, g_rcCanvas.left, g_rcCanvas.top,
  248.                 g_rcCanvas.right - g_rcCanvas.left,
  249.                 g_rcCanvas.bottom - g_rcCanvas.top, FALSE);
  250.         InflateRect(&g_rcCanvas, -1, -1);
  251.         CopyRect(&g_rc, &g_rcCanvas);
  252.         InflateRect(&g_rc, -(g_rcCanvas.right - g_rcCanvas.left) / 8,
  253.                     -(g_rcCanvas.bottom - g_rcCanvas.top) / 4);
  254.         InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  255.         SetFocus(GetDlgItem(hwnd, IDC_BARCODE));
  256.         return 0;
  257.     case WM_PAINT:
  258.         hdc = BeginPaint(hwnd, &ps);          
  259.         IntersectClipRect(hdc, g_rcCanvas.left, g_rcCanvas.top,
  260.                     g_rcCanvas.right, g_rcCanvas.bottom);
  261.         // draw bg
  262.         hBrush = SelectObject(hdc, 
  263.                     CreateSolidBrush(RGB(255, 255, 232)));
  264.         PatBlt(hdc, g_rcCanvas.left, g_rcCanvas.top, 
  265.                 g_rcCanvas.right - g_rcCanvas.left,
  266.                 g_rcCanvas.bottom - g_rcCanvas.top, PATCOPY);
  267.         DeleteObject(SelectObject(hdc, hBrush));
  268.  
  269.         if (g_bInvalidData1 || g_bInvalidData2)
  270.         {
  271.             DrawText(hdc, "Invalid Data!", -1, &g_rcCanvas,
  272.                     DT_SINGLELINE | DT_CENTER | DT_VCENTER);
  273.         }
  274.         else
  275.         {
  276.             if (SendDlgItemMessage(hwnd, IDC_WYSIWYG,
  277.                         BM_GETCHECK, 0, 0) == 0)
  278.                 drawBarcode(hwnd, hdc, 0, g_hbar, &g_rc);
  279.             else
  280.                 drawBarcode(hwnd, hdc, g_hPrintDC, g_hbar, &g_rc);
  281.         
  282.             XORDottedFrame (hdc, &g_rc);
  283.         }
  284.         EndPaint(hwnd, &ps);
  285.         return 0;                             
  286.     case WM_MOUSEMOVE:  
  287.         if (!nDrag)
  288.         {
  289.             pt.x = LOWORD(lParam);
  290.             pt.y = HIWORD(lParam);
  291.             if (!PtInRect(&g_rcCanvas, pt)) 
  292.             {
  293.                 SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)));
  294.                 break;
  295.             }
  296.  
  297.             i = hitTest(LOWORD(lParam), HIWORD(lParam), &g_rc);
  298.             switch (i) {
  299.             case HT_LEFT:
  300.             case HT_RIGHT:
  301.                 SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZEWE)));
  302.                 break;
  303.             case HT_TOP:
  304.             case HT_BOTTOM:
  305.                 SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENS)));
  306.                 break;
  307.             case HT_LEFTTOP:
  308.             case HT_RIGHTBOTTOM:
  309.                 SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENWSE)));
  310.                 break;
  311.             case HT_LEFTBOTTOM:
  312.             case HT_RIGHTTOP:
  313.                 SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENESW)));
  314.                 break;
  315.             case HT_INSIDE:
  316.                 SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZE)));
  317.                 break;
  318.             default:
  319.                 SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)));
  320.             }
  321.         }
  322.         else
  323.         {
  324.             hdc = GetDC(hwnd);       
  325.             XORDottedFrame(hdc, &rcPrev);
  326.             switch (nDrag) {
  327.             case HT_LEFT:
  328.                 rcPrev.left = g_rc.left + LOWORD(lParam) - pt.x;
  329.                 break;
  330.             case HT_RIGHT:
  331.                 rcPrev.right = g_rc.right + LOWORD(lParam) - pt.x;
  332.                 break;
  333.             case HT_TOP:
  334.                 rcPrev.top = g_rc.top + HIWORD(lParam) - pt.y;
  335.                 break;
  336.             case HT_BOTTOM:
  337.                 rcPrev.bottom = g_rc.bottom + HIWORD(lParam) - pt.y;
  338.                 break;
  339.             case HT_LEFTTOP:
  340.                 rcPrev.left = g_rc.left + LOWORD(lParam) - pt.x;
  341.                 rcPrev.top = g_rc.top + HIWORD(lParam) - pt.y;
  342.                 break;
  343.             case HT_RIGHTBOTTOM:
  344.                 rcPrev.right = g_rc.right + LOWORD(lParam) - pt.x;
  345.                 rcPrev.bottom = g_rc.bottom + HIWORD(lParam) - pt.y;
  346.                 break;
  347.             case HT_LEFTBOTTOM:
  348.                 rcPrev.left = g_rc.left + LOWORD(lParam) - pt.x;
  349.                 rcPrev.bottom = g_rc.bottom + HIWORD(lParam) - pt.y;
  350.                 break;
  351.             case HT_RIGHTTOP:
  352.                 rcPrev.right = g_rc.right + LOWORD(lParam) - pt.x;
  353.                 rcPrev.top = g_rc.top + HIWORD(lParam) - pt.y;
  354.                 break;
  355.             case HT_INSIDE:              
  356.                 CopyRect(&rcPrev, &g_rc);
  357.                 OffsetRect(&rcPrev, LOWORD(lParam) - pt.x,
  358.                             HIWORD(lParam) - pt.y);
  359.                 break;
  360.             default:
  361.                 ;
  362.             }
  363.             XORDottedFrame(hdc, &rcPrev);
  364.             ReleaseDC(hwnd, hdc);
  365.         }
  366.         return 0;
  367.     case WM_LBUTTONDOWN:
  368.         pt.x = LOWORD(lParam);
  369.         pt.y = HIWORD(lParam);
  370.         if (!PtInRect(&g_rcCanvas, pt)) break;
  371.         nDrag = hitTest(pt.x, pt.y, &g_rc);
  372.         if (nDrag)
  373.         {                 
  374.             SetCapture(hwnd);
  375.             CopyRect(&rcPrev, &g_rcCanvas);
  376.             ClientToScreen(hwnd, (LPPOINT)&rcPrev);
  377.             ClientToScreen(hwnd, ((LPPOINT)&rcPrev) + 1);
  378.             ClipCursor(&rcPrev);
  379.             CopyRect(&rcPrev, &g_rc);
  380.             hdc = GetDC(hwnd);       
  381.             XORDottedFrame(hdc, &rcPrev);
  382.             ReleaseDC(hwnd, hdc);
  383.         }
  384.         return 0;        
  385.     case WM_LBUTTONUP:                               
  386.         if (GetCapture() == hwnd)
  387.         {
  388.             if (rcPrev.left > rcPrev.right)
  389.             {
  390.                 i = rcPrev.left; rcPrev.left = rcPrev.right; rcPrev.right = i;
  391.             }
  392.             if (rcPrev.top > rcPrev.bottom)
  393.             {
  394.                 i = rcPrev.top; rcPrev.top = rcPrev.bottom; rcPrev.bottom = i;
  395.             }
  396.             nDrag = 0;
  397.             ClipCursor(NULL);
  398.             ReleaseCapture();
  399.             hdc = GetDC(hwnd);       
  400.             XORDottedFrame(hdc, &rcPrev);
  401.             ReleaseDC(hwnd, hdc);
  402.             if (!EqualRect(&rcPrev, &g_rc))
  403.             {
  404.                 CopyRect(&g_rc, &rcPrev);
  405.                 InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  406.             }
  407.             return 0;
  408.         }
  409.         break;               
  410.     case WM_SETFOCUS:
  411.         SetFocus(GetDlgItem(hwnd, IDC_BARCODE));
  412.         return 0;
  413.     case WM_COMMAND:
  414.         return cmdProc(hwnd, wParam, lParam);
  415.     case WM_CLOSE:
  416.         break;
  417.     case WM_DESTROY:           
  418.         if (g_hbar) BarDestroy(g_hbar);
  419.         if (g_hPrintDC) DeleteDC(g_hPrintDC);
  420.         if (g_hDevMode) GlobalFree(g_hDevMode);
  421.         if (g_hDevNames) GlobalFree(g_hDevNames);
  422.         PostQuitMessage(0);
  423.         return 0;
  424.     }
  425.     
  426.     return DefWindowProc(hwnd, msg, wParam, lParam);
  427. }
  428.  
  429. static int hitTest(int x, int y, LPRECT lprc)
  430. {                                    
  431.     int        d = 2;
  432.     int        n;
  433.  
  434.     if (x < lprc->left - d)
  435.         return 0;
  436.     else if (x <= lprc->left + d)
  437.         n = HT_LEFT;
  438.     else if (x < lprc->right - d)
  439.         n = HT_INSIDE;
  440.     else if (x <= lprc->right + d)
  441.         n = HT_RIGHT;
  442.     else
  443.         return 0;
  444.     
  445.     if (y < lprc->top - d)
  446.         return 0;
  447.     else if (y <= lprc->top + d)
  448.         switch (n) {
  449.         case HT_LEFT:
  450.             n = HT_LEFTTOP; break;
  451.         case HT_RIGHT:
  452.             n = HT_RIGHTTOP; break;
  453.         default:
  454.             n = HT_TOP;
  455.         }
  456.     else if (y < lprc->bottom - d)
  457.         ;
  458.     else if (y <= lprc->bottom + d)
  459.         switch (n) {
  460.         case HT_LEFT:
  461.             n = HT_LEFTBOTTOM; break;
  462.         case HT_RIGHT:
  463.             n = HT_RIGHTBOTTOM; break;
  464.         default:
  465.             n = HT_BOTTOM;
  466.         }
  467.     else
  468.         return 0;
  469.     
  470.     return n;
  471. }
  472.  
  473. static void XORDottedFrame (HDC hdc, LPRECT prc)
  474. {
  475.     HPEN    hp;
  476.     int        r2;
  477.     int        m;
  478.  
  479.     r2 = SetROP2(hdc, R2_NOTXORPEN);
  480.     hp = SelectObject(hdc, CreatePen (PS_DOT, 0, RGB (0, 0, 0)));
  481.        m = SetBkMode(hdc, TRANSPARENT);
  482.     MoveTo(hdc, prc->left - 1, prc->top - 1);
  483.     LineTo(hdc, prc->right, prc->top - 1); 
  484.     LineTo(hdc, prc->right, prc->bottom);
  485.     LineTo(hdc, prc->left - 1, prc->bottom);
  486.     LineTo(hdc, prc->left - 1, prc->top - 1);
  487.     DeleteObject(SelectObject(hdc, hp));
  488.     SetROP2(hdc, r2);
  489.        SetBkMode(hdc, m);
  490. }
  491.  
  492. static long cmdProc(HWND hwnd, WPARAM wParam, LPARAM lParam)
  493. {                                
  494.     int            iType;
  495.     static char    buf[64];
  496.     static char    buf2[64];
  497.     DWORD        dwIndex;             
  498.     FARPROC        lpfnDlgProc;                              
  499.     HINSTANCE    hInst;
  500.     static CHOOSEFONT    cf;
  501.     static CHOOSECOLOR    cc;
  502.     static PRINTDLG        pd;
  503.     static DWORD        dwCustColors[16];
  504.     HWND        hCtl;
  505.     RECT        rc;
  506.     
  507.     switch(wParam) {
  508.     case IDC_ABOUT:
  509.         hInst = GetWindowWord(hwnd, GWW_HINSTANCE);
  510.         lpfnDlgProc = MakeProcInstance((FARPROC)AboutDlgProc, hInst);
  511.         DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), hwnd, lpfnDlgProc);
  512.         FreeProcInstance(lpfnDlgProc);
  513.         return 0;
  514.     case IDC_BTNFONT:
  515.         memset(&cf, 0, sizeof(cf));
  516.         cf.lStructSize = sizeof(CHOOSEFONT);
  517.         cf.hwndOwner = hwnd;
  518.         cf.lpLogFont = &g_logfont;
  519.         cf.iPointSize = 0;
  520.         cf.rgbColors = g_clfFg;
  521.         cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_EFFECTS;
  522.         if (g_hPrintDC) 
  523.         {
  524.             if (!g_hPrintDC) MessageBeep(0);
  525.             cf.hDC = g_hPrintDC;
  526.             cf.Flags |= CF_PRINTERFONTS;
  527.         }
  528.         if (ChooseFont(&cf))
  529.         {
  530.             SetWindowText(GetDlgItem(hwnd, IDC_FONTNAME), 
  531.                     g_logfont.lfFaceName);
  532.             wsprintf(buf, "%d", cf.iPointSize / 10);
  533.             if (cf.iPointSize % 10 > 0)
  534.                 wsprintf(buf + strlen(buf), ".%d", cf.iPointSize % 10);
  535.             SetWindowText(GetDlgItem(hwnd, IDC_POINT), buf);
  536.             g_clfFg = cf.rgbColors;
  537.             InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  538.         }
  539.         return 0;
  540.     case IDC_BG:
  541.         memset(&cc, 0, sizeof(cc));
  542.         cc.lStructSize = sizeof(CHOOSECOLOR);
  543.         cc.hwndOwner = hwnd;
  544.         cc.rgbResult = g_clfBg;
  545.         cc.Flags = CC_PREVENTFULLOPEN | CC_RGBINIT;
  546.         cc.lpCustColors = dwCustColors;
  547.         if (ChooseColor(&cc))
  548.         {
  549.             g_clfBg = cc.rgbResult;
  550.             SendDlgItemMessage(hwnd, IDC_TRANSPARENT, BM_SETCHECK, 0, 0);
  551.             g_iBkMode = OPAQUE;
  552.             InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  553.         }
  554.         return 0;
  555.     case IDC_PRINT:
  556.         memset(&pd, 0, sizeof(pd));
  557.         pd.lStructSize = sizeof(pd);
  558.         pd.hwndOwner = hwnd;
  559.         pd.nFromPage = pd.nToPage = 1;
  560.         pd.nMinPage = pd.nMaxPage = 1;
  561.         pd.Flags = PD_NOSELECTION | PD_ALLPAGES 
  562.                     | PD_RETURNDC | PD_USEDEVMODECOPIES;
  563.         pd.hDevMode = g_hDevMode;
  564.         pd.hDevNames = g_hDevNames;
  565.         if (PrintDlg(&pd)) 
  566.         {
  567.             if (g_hPrintDC) DeleteDC(g_hPrintDC);
  568.             g_hPrintDC = pd.hDC;
  569.             g_hDevMode = pd.hDevMode;
  570.             g_hDevNames = pd.hDevNames;
  571.             CopyRect(&rc, &g_rc);
  572.             OffsetRect(&rc, -g_rcCanvas.left, -g_rcCanvas.top);
  573.             printBarcode(hwnd, g_hPrintDC, g_hbar, &rc);
  574.             // TODO: if WYSIWYG, refresh
  575.         }
  576.         else
  577.         {
  578.             g_hDevMode = pd.hDevMode;
  579.             g_hDevNames = pd.hDevNames;
  580.         }
  581.         // printer config may have changed
  582.         InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  583.         return 0;
  584.     case IDC_TRANSPARENT:
  585.         if (HIWORD(lParam) == BN_CLICKED)
  586.         {
  587.             if (SendDlgItemMessage(hwnd, IDC_TRANSPARENT,
  588.                         BM_GETCHECK, 0, 0) == 0)
  589.                 g_iBkMode = OPAQUE;
  590.             else
  591.                 g_iBkMode = TRANSPARENT;
  592.             InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  593.             return 0;
  594.         }
  595.         break;
  596.     case IDC_WYSIWYG:
  597.         if (HIWORD(lParam) == BN_CLICKED)
  598.         {
  599.             InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  600.             return 0;
  601.         }
  602.         break;
  603.     case IDC_BARCODE:
  604.         if (HIWORD(lParam) == CBN_SELCHANGE)
  605.         {
  606.             dwIndex = SendDlgItemMessage(hwnd, IDC_BARCODE, CB_GETCURSEL, 0, 0);
  607.             iType = (int) SendDlgItemMessage(hwnd, IDC_BARCODE, 
  608.                         CB_GETITEMDATA, (WPARAM)dwIndex, (LPARAM)0);
  609.             if (g_hbar && g_iType == iType) return 0;
  610.             if (g_hbar) BarDestroy(g_hbar);
  611.             g_iType = iType;
  612.             g_hbar = BarCreate(iType, 0);
  613.             SetWindowText(GetDlgItem(hwnd, IDC_MESSAGE), "");
  614.             SetWindowText(GetDlgItem(hwnd, IDC_ADDONMESG), "");
  615.  
  616.             BarGetData(g_hbar, g_tmp, sizeof(g_tmp), NULL, 0);
  617.             SendDlgItemMessage(hwnd, IDC_DATA, WM_SETTEXT, 0, 
  618.                 (LONG)(LPSTR)g_tmp);
  619.  
  620.             BarGetAddOnData(g_hbar, g_tmp, sizeof(g_tmp), NULL, 0);
  621.             if (!g_tmp[0])
  622.             {
  623.                 EnableWindow(GetDlgItem(hwnd, IDC_ADDONDATA), FALSE);
  624.                 EnableWindow(GetDlgItem(hwnd, IDC_ADDONMESG), FALSE);
  625.             }
  626.             else
  627.             {
  628.                 EnableWindow(GetDlgItem(hwnd, IDC_ADDONDATA), TRUE);
  629.                 EnableWindow(GetDlgItem(hwnd, IDC_ADDONMESG), TRUE);
  630.             }
  631.             SendDlgItemMessage(hwnd, IDC_ADDONDATA, WM_SETTEXT, 0, 
  632.                 (LONG)(LPSTR)g_tmp);
  633.  
  634.             g_bInvalidData1 = g_bInvalidData2 = FALSE;
  635.             InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  636.             return 0;
  637.         }   
  638.         break;
  639.     case IDC_STYLE:
  640.         if (HIWORD(lParam) == LBN_SELCHANGE)
  641.         {
  642.             InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  643.             return 0;
  644.         }   
  645.         break;
  646.     case IDC_ORIENT:
  647.         if (HIWORD(lParam) == CBN_SELCHANGE)
  648.         {
  649.             int    n;
  650.             dwIndex = SendDlgItemMessage(hwnd, IDC_ORIENT, CB_GETCURSEL, 0, 0);
  651.             SendDlgItemMessage(hwnd, IDC_ORIENT, CB_GETLBTEXT, 
  652.                     (WPARAM)dwIndex, (LPARAM)(LPSTR)buf);
  653.             n = atoi(buf);
  654.             if ((g_iOrient - n) % 180 != 0)
  655.             {
  656.                 int tmp;
  657.                 tmp = g_rc.left; g_rc.left = g_rc.top; g_rc.top = tmp;
  658.                 tmp = g_rc.right; g_rc.right = g_rc.bottom; g_rc.bottom = tmp;
  659.                 OffsetRect(&g_rc, -(g_rc.left - g_rcCanvas.left - 5),
  660.                             -(g_rc.top - g_rcCanvas.top - 5));
  661.             }
  662.             g_iOrient = n;
  663.             InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  664.             return 0;
  665.         }   
  666.         break;
  667.     case IDC_DATA:
  668.     case IDC_MESSAGE:
  669.         if (HIWORD(lParam) == EN_KILLFOCUS)
  670.         {
  671.             SendDlgItemMessage(hwnd, IDC_DATA, WM_GETTEXT, 
  672.                 sizeof(buf), (LPARAM)(LPSTR)buf);
  673.             SendDlgItemMessage(hwnd, IDC_MESSAGE, WM_GETTEXT, 
  674.                 sizeof(buf2), (LPARAM)(LPSTR)buf2);
  675.             if (g_hbar)
  676.             {
  677.                 g_bInvalidData1 = FALSE;
  678.                 if (buf[0] == 0)
  679.                 {
  680.                     BarGetData(g_hbar, g_tmp, sizeof(g_tmp), NULL, 0);
  681.                     SendDlgItemMessage(hwnd, IDC_DATA, WM_SETTEXT, 0, 
  682.                             (LONG)(LPSTR)g_tmp);
  683.                 }
  684.                 else if (!BarSetData(g_hbar, buf, lstrlen(buf), 
  685.                             buf2, lstrlen(buf2)))
  686.                 {
  687.                     g_bInvalidData1 = TRUE;
  688.                 }
  689.             }
  690.             InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  691.             return 0;
  692.         }   
  693.         break;
  694.     case IDC_ADDONDATA:
  695.     case IDC_ADDONMESG:
  696.         if (HIWORD(lParam) == EN_KILLFOCUS)
  697.         {
  698.             SendDlgItemMessage(hwnd, IDC_ADDONDATA, WM_GETTEXT, 
  699.                 sizeof(buf), (LPARAM)(LPSTR)buf);
  700.             SendDlgItemMessage(hwnd, IDC_ADDONMESG, WM_GETTEXT, 
  701.                 sizeof(buf2), (LPARAM)(LPSTR)buf2);
  702.             if (g_hbar)
  703.             {
  704.                 g_bInvalidData2 = FALSE;
  705.                 if (buf[0] == 0)
  706.                 {
  707.                     BarGetAddOnData(g_hbar, g_tmp, sizeof(g_tmp), NULL, 0);
  708.                     SendDlgItemMessage(hwnd, IDC_ADDONDATA, WM_SETTEXT, 0, 
  709.                             (LONG)(LPSTR)g_tmp);
  710.                 }
  711.                 else if (!BarSetAddOnData(g_hbar, buf, lstrlen(buf), 
  712.                         buf2, lstrlen(buf2)))
  713.                 {
  714.                     g_bInvalidData2 = TRUE;
  715.                 }
  716.             }
  717.             InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  718.             return 0;
  719.         }   
  720.         break;
  721.     case IDOK:
  722.         hCtl = GetFocus();
  723.         if (hCtl && (hCtl = GetNextDlgTabItem(hwnd, hCtl, FALSE)))
  724.             SetFocus(hCtl);
  725.         return 0;
  726.     case IDC_BTNADVANCED:
  727.         hInst = GetWindowWord(hwnd, GWW_HINSTANCE);
  728.         lpfnDlgProc = MakeProcInstance((FARPROC)AdvancedDlgProc, hInst);
  729.         if (DialogBox(hInst, MAKEINTRESOURCE(IDD_ADVANCED), hwnd, lpfnDlgProc))
  730.             InvalidateRect(hwnd, &g_rcCanvas, FALSE);
  731.         FreeProcInstance(lpfnDlgProc);
  732.         return 0;
  733.     default:
  734.         break;
  735.     }
  736.  
  737.     return DefWindowProc(hwnd, WM_COMMAND, wParam, lParam);
  738. }
  739.  
  740. static DWORD getStyle(HWND hwnd)
  741. {
  742.     static int        ai[50];   
  743.     int        i, c;
  744.     DWORD    dw;
  745.  
  746.     c = (int)SendDlgItemMessage(hwnd, IDC_STYLE, LB_GETSELITEMS, 
  747.             (WPARAM)50, (LPARAM)(LPINT)ai);
  748.     dw = 0;        
  749.     for (i = 0; i < c; i++)
  750.         dw |= SendDlgItemMessage(hwnd, IDC_STYLE, LB_GETITEMDATA, 
  751.                     (WPARAM)ai[i], (LPARAM)0);
  752.  
  753.     return dw;
  754. }
  755.  
  756. static void drawBarcode(HWND hwnd, HDC hdc, HDC hicTarget, 
  757.                 HBARCODE hBar, LPRECT lprc)
  758. {
  759.     HFONT    hf, hf2;
  760.     LOGFONT    lf;                       
  761.     RECT    rc;
  762.  
  763.     if (!g_hbar || !hdc) return;
  764.  
  765.     if (!hicTarget)
  766.     {
  767.         SetBkMode(hdc, g_iBkMode); 
  768.         SetBkColor(hdc, g_clfBg); 
  769.         SetTextColor(hdc, g_clfFg);
  770.  
  771.         hf2 = CreateFontIndirect(&g_logfont);
  772.         hf = SelectObject(hdc, hf2);
  773.  
  774.         BarDraw(g_hbar, hdc, NULL, lprc, g_iOrient, getStyle(hwnd));
  775.             
  776.         SelectObject(hdc, hf);
  777.         DeleteObject(hf2);
  778.     }
  779.     else
  780.     {
  781.         SetBkMode(hicTarget, g_iBkMode); 
  782.         SetBkColor(hicTarget, g_clfBg); 
  783.         SetTextColor(hicTarget, g_clfFg);
  784.  
  785.         SetMapMode(hdc, MM_ANISOTROPIC);
  786.         SetWindowExt(hdc, 1440, 1440);
  787.         SetViewportExt(hdc, GetDeviceCaps(hdc, LOGPIXELSX),
  788.                     -GetDeviceCaps(hdc, LOGPIXELSY));
  789.         SetMapMode(hicTarget, MM_TWIPS);
  790.  
  791.         CopyRect(&rc, lprc);
  792.         DPtoLP(hdc, (LPPOINT)&rc, 2);
  793.  
  794.         // physical coord to logical
  795.         memcpy(&lf, &g_logfont, sizeof(lf));
  796.         lf.lfHeight = MulDiv(lf.lfHeight, 1440, 
  797.                         GetDeviceCaps(hdc, LOGPIXELSY));
  798.         lf.lfWidth = 0;
  799.         hf2 = CreateFontIndirect(&lf);
  800.         hf = SelectObject(hicTarget, hf2);
  801.  
  802.         BarDraw(g_hbar, hdc, hicTarget, &rc, g_iOrient, getStyle(hwnd));
  803.             
  804.         SetMapMode(hdc, MM_TEXT);
  805.         SetMapMode(hicTarget, MM_TEXT);
  806.  
  807.         SelectObject(hicTarget, hf);
  808.         DeleteObject(hf2);
  809.     }
  810. }
  811.  
  812. static void printBarcode(HWND hwnd, HDC hdcPrint, HBARCODE hBar, LPRECT lprc)
  813. {
  814.     HFONT    hf, hf2;
  815.     LOGFONT    lf;                       
  816.     RECT    rc;
  817.     HDC        hdcWnd;
  818.     FARPROC    lpfnPrintDlgProc;
  819.     FARPROC    lpfnAbortProc;
  820.     HINSTANCE    hInst = GetWindowWord(hwnd, GWW_HINSTANCE);
  821.     
  822.     if (!g_hbar || !hdcPrint) return;
  823.  
  824.     lpfnPrintDlgProc = MakeProcInstance((FARPROC)PrintDlgProc, hInst);
  825.     g_hPrintDlg = CreateDialog(hInst, MAKEINTRESOURCE(IDD_PRINTABORT),
  826.                     hwnd, lpfnPrintDlgProc);
  827.     lpfnAbortProc = MakeProcInstance((FARPROC)AbortProc, hInst);
  828.     Escape(hdcPrint, SETABORTPROC, 0, (LPSTR)lpfnAbortProc, NULL);
  829.  
  830.     SetBkMode(hdcPrint, g_iBkMode); 
  831.     SetBkColor(hdcPrint, g_clfBg); 
  832.     SetTextColor(hdcPrint, g_clfFg);
  833.  
  834.     hdcWnd = GetDC(hwnd);
  835.     SetMapMode(hdcWnd, MM_ANISOTROPIC);
  836.     SetWindowExt(hdcWnd, 1440, 1440);
  837.     SetViewportExt(hdcWnd, GetDeviceCaps(hdcWnd, LOGPIXELSX),
  838.                     -GetDeviceCaps(hdcWnd, LOGPIXELSY));
  839.     SetMapMode(hdcPrint, MM_TWIPS);
  840.  
  841.     CopyRect(&rc, lprc);
  842.     DPtoLP(hdcWnd, (LPPOINT)&rc, 2);
  843.  
  844.     // physical coord to logical
  845.     memcpy(&lf, &g_logfont, sizeof(lf));
  846.     lf.lfHeight = MulDiv(lf.lfHeight, 1440, 
  847.                         GetDeviceCaps(hdcWnd, LOGPIXELSY));
  848.     lf.lfWidth = 0;
  849.     hf2 = CreateFontIndirect(&lf);
  850.     hf = SelectObject(hdcPrint, hf2);
  851.  
  852.     if (Escape(hdcPrint, STARTDOC, 7, "Barcode", NULL) > 0)
  853.     {
  854.         BarDraw(g_hbar, hdcPrint, NULL, &rc, g_iOrient, getStyle(hwnd));
  855.         if (Escape(hdcPrint, NEWFRAME, 0, NULL, NULL) > 0)
  856.             Escape(hdcPrint, ENDDOC, 0, NULL, NULL);
  857.     }
  858.             
  859.     SetMapMode(hdcWnd, MM_TEXT);
  860.     SetMapMode(hdcPrint, MM_TEXT);
  861.  
  862.     SelectObject(hdcPrint, hf);
  863.     DeleteObject(hf2);
  864.     
  865.     ReleaseDC(hwnd, hdcWnd);
  866.  
  867.     if (g_hPrintDlg)
  868.     {
  869.         EnableWindow(hwnd, TRUE);
  870.         DestroyWindow(g_hPrintDlg);
  871.         g_hPrintDlg = 0;
  872.     }
  873.  
  874.     FreeProcInstance(lpfnPrintDlgProc);
  875.     FreeProcInstance(lpfnAbortProc);
  876. }
  877.  
  878. BOOL FAR PASCAL _export AboutDlgProc(HWND hwnd, UINT msg, 
  879.                             WPARAM wParam, LPARAM lParam)
  880. {
  881.     switch(msg) {
  882.     case WM_INITDIALOG:
  883.         return TRUE;
  884.     case WM_COMMAND:
  885.         switch(wParam) {
  886.         case IDOK:
  887.         case IDCANCEL:
  888.             EndDialog(hwnd, 0);
  889.             return TRUE;
  890.         }
  891.         break;
  892.     }
  893.     return FALSE;
  894. }
  895.  
  896. BOOL FAR PASCAL _export PrintDlgProc(HWND hDlg, UINT msg, 
  897.                             WPARAM wParam, LPARAM lParam)
  898. {
  899.     switch(msg) {
  900.     case WM_INITDIALOG:      
  901.         g_bUserAbort = FALSE;
  902.         EnableWindow(GetParent(hDlg), FALSE);
  903.         return TRUE;
  904.     case WM_COMMAND:
  905.         g_bUserAbort = TRUE;
  906.         EnableWindow(GetParent(hDlg), TRUE);
  907.         DestroyWindow(hDlg);
  908.         return TRUE;
  909.     case WM_DESTROY:
  910.         g_hPrintDlg = 0;
  911.         return TRUE;
  912.     }
  913.     return FALSE;
  914. }
  915.  
  916. BOOL FAR PASCAL _export AbortProc(HDC hdcPrint, short sCode)
  917. {
  918.     MSG        msg;
  919.     
  920.     while (!g_bUserAbort && PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  921.     {
  922.         if (!g_hPrintDlg || !IsDialogMessage(g_hPrintDlg, &msg))
  923.         {
  924.             TranslateMessage(&msg);
  925.             DispatchMessage(&msg);
  926.         }
  927.     }
  928.  
  929.     return !g_bUserAbort;
  930. }
  931.  
  932. BOOL FAR PASCAL _export AdvancedDlgProc(HWND hwnd, UINT msg, 
  933.                             WPARAM wParam, LPARAM lParam)
  934. {
  935.     int        i, n;
  936.     
  937.     switch(msg) {
  938.     case WM_INITDIALOG:
  939.         wsprintf(g_tmp, "%d", BarGetClearArea(g_hbar, BGCA_LEFT));
  940.         SetWindowText(GetDlgItem(hwnd, IDC_SPLEFT), g_tmp);
  941.         wsprintf(g_tmp, "%d", BarGetClearArea(g_hbar, BGCA_RIGHT));
  942.         SetWindowText(GetDlgItem(hwnd, IDC_SPRIGHT), g_tmp);
  943.         wsprintf(g_tmp, "%d", BarGetClearArea(g_hbar, BGCA_TOP));
  944.         SetWindowText(GetDlgItem(hwnd, IDC_SPTOP), g_tmp);
  945.         wsprintf(g_tmp, "%d", BarGetClearArea(g_hbar, BGCA_BOTTOM));
  946.         SetWindowText(GetDlgItem(hwnd, IDC_SPBOTTOM), g_tmp);
  947.  
  948.         wsprintf(g_tmp, "%d", BarGetClearArea(g_hbar, BGCA_MIDDLE));
  949.         if (g_tmp[0] == '0')
  950.             EnableWindow(GetDlgItem(hwnd, IDC_SPMIDDLE), FALSE);
  951.         else
  952.             SetWindowText(GetDlgItem(hwnd, IDC_SPMIDDLE), g_tmp);
  953.  
  954.         n = BarGetNumBarExts(g_hbar);
  955.         for (i = 0; i < n; i++)
  956.         {
  957.             wsprintf(g_tmp, "%d", BarGetBarExt(g_hbar, i));
  958.             SetWindowText(GetDlgItem(hwnd, IDC_BAR0 + i), g_tmp);
  959.         }
  960.         for (i = n; i < 4; i++) 
  961.             EnableWindow(GetDlgItem(hwnd, IDC_BAR0 + i), FALSE);
  962.             
  963.         n = BarGetNumSpaceExts(g_hbar);
  964.         for (i = 0; i < n; i++)
  965.         {
  966.             wsprintf(g_tmp, "%d", BarGetSpaceExt(g_hbar, i));
  967.             SetWindowText(GetDlgItem(hwnd, IDC_SPACE0 + i), g_tmp);
  968.         }
  969.         for (i = n; i < 4; i++) 
  970.             EnableWindow(GetDlgItem(hwnd, IDC_SPACE0 + i), FALSE);
  971.  
  972.         wsprintf(g_tmp, "%d", BarGetInterCharExt(g_hbar));
  973.         if (g_tmp[0] == '0')
  974.             EnableWindow(GetDlgItem(hwnd, IDC_INTERCHARGAP), FALSE);
  975.         else
  976.             SetWindowText(GetDlgItem(hwnd, IDC_INTERCHARGAP), g_tmp);
  977.  
  978.         return TRUE;
  979.     case WM_COMMAND:
  980.         switch(wParam) {
  981.         case IDOK:
  982.             SendDlgItemMessage(hwnd, IDC_SPLEFT, WM_GETTEXT, 
  983.                 sizeof(g_tmp), (LPARAM)(LPSTR)g_tmp);
  984.             BarSetClearArea(g_hbar, BGCA_LEFT, atoi(g_tmp));
  985.             SendDlgItemMessage(hwnd, IDC_SPRIGHT, WM_GETTEXT, 
  986.                 sizeof(g_tmp), (LPARAM)(LPSTR)g_tmp);
  987.             BarSetClearArea(g_hbar, BGCA_RIGHT, atoi(g_tmp));
  988.             SendDlgItemMessage(hwnd, IDC_SPMIDDLE, WM_GETTEXT, 
  989.                 sizeof(g_tmp), (LPARAM)(LPSTR)g_tmp);
  990.             BarSetClearArea(g_hbar, BGCA_MIDDLE, atoi(g_tmp));
  991.             SendDlgItemMessage(hwnd, IDC_SPTOP, WM_GETTEXT, 
  992.                 sizeof(g_tmp), (LPARAM)(LPSTR)g_tmp);
  993.             BarSetClearArea(g_hbar, BGCA_TOP, atoi(g_tmp));
  994.             SendDlgItemMessage(hwnd, IDC_SPBOTTOM, WM_GETTEXT, 
  995.                 sizeof(g_tmp), (LPARAM)(LPSTR)g_tmp);
  996.             BarSetClearArea(g_hbar, BGCA_BOTTOM, atoi(g_tmp));
  997.  
  998.             n = BarGetNumBarExts(g_hbar);
  999.             for (i = 0; i < n; i++)
  1000.             {
  1001.                 SendDlgItemMessage(hwnd, IDC_BAR0 + i, WM_GETTEXT, 
  1002.                     sizeof(g_tmp), (LPARAM)(LPSTR)g_tmp);
  1003.                 BarSetBarExt(g_hbar, i, atoi(g_tmp));
  1004.             }
  1005.             
  1006.             n = BarGetNumSpaceExts(g_hbar);
  1007.             for (i = 0; i < n; i++)
  1008.             {
  1009.                 SendDlgItemMessage(hwnd, IDC_SPACE0 + i, WM_GETTEXT, 
  1010.                     sizeof(g_tmp), (LPARAM)(LPSTR)g_tmp);
  1011.                 BarSetSpaceExt(g_hbar, i, atoi(g_tmp));
  1012.             }
  1013.  
  1014.             SendDlgItemMessage(hwnd, IDC_INTERCHARGAP, WM_GETTEXT, 
  1015.                     sizeof(g_tmp), (LPARAM)(LPSTR)g_tmp);
  1016.             BarSetInterCharExt(g_hbar, atoi(g_tmp));
  1017.  
  1018.             EndDialog(hwnd, TRUE);
  1019.             return TRUE;
  1020.         case IDCANCEL:
  1021.             EndDialog(hwnd, FALSE);
  1022.             return TRUE;
  1023.         }
  1024.         break;
  1025.     }
  1026.     return FALSE;
  1027. }
  1028.  
  1029.